package com.hzhr.iot.user.service;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.CygQuery;
import com.hzhr.iot.core.annotation.CygQuerys;
import com.hzhr.iot.core.annotation.CygService;
import com.hzhr.iot.core.constant.AccessModeEnum;
import com.hzhr.iot.core.constant.CommonOptions;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.core.util.HzhrTypeUtil;
import com.hzhr.iot.user.constant.UserOptions;
import com.hzhr.iot.user.constant.UserOptionsName;
import com.hzhr.iot.user.constant.UserOptionsTypeName;
import com.hzhr.iot.user.constant.User_ErrorsEnum;
import com.hzhr.iot.user.convertor.custom.RoleCustomConvertor;
import com.hzhr.iot.user.dao.RoleDao;
import com.hzhr.iot.user.entity.RoleEntity;
import com.hzhr.iot.user.entity.ext.RoleEntityExt;
import com.hzhr.iot.user.model.company.CompanyModel;
import com.hzhr.iot.user.model.role.RoleGetModel;
import com.hzhr.iot.user.model.role.RoleModel;
import com.hzhr.iot.user.queryModel.custom.RoleCustomQueryModel;
import com.hzhr.iot.user.service.base.BaseService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@CygService(entity = RoleEntity.class, model = RoleModel.class)
@CygQuerys({
        @CygQuery(name = "_equal_id", query = "equal_id", type = Integer.class),
        @CygQuery(name = "_equal_name", query = "equal_name", type = String.class),
        @CygQuery(name = "_equal_companyId", query = "equal_companyId", type = Integer.class),
})
public class RoleService extends BaseService {
    @Autowired
    RoleDao roleDao;
    @Autowired
    RoleCustomConvertor roleCustomConvertor;
    @Autowired
    CompanyService companyService;
    @Autowired
    UserOptions userOptions;

    //region javadoc注释 : get
    /**
     * 查询角色 <br/><br/>
     * 简介&nbsp;:&nbsp;查询角色 <br/>
     * 步骤&nbsp;: <br/>
     * 1.&nbsp;查询角色&nbsp;:&nbsp;(√) <br/>
     * &nbsp;根据条件参数查询角色(ROLE)； <br/>
     * 2.&nbsp;返回信息&nbsp;:&nbsp;(√) <br/>
     * &nbsp;根据条件参数和查询到的结果组装响应并返回； <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_total : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示总数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _is_paging : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否分页;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _page : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 页数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _count : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 每页数量;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where role.id = #{_equal_id};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where role.id = #{_equal_name};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_companyId : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where role.companyId = #{_equal_companyId};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @throws ServiceException <br/>
     * @see RoleGetModel result <br/>
     */ 
    //endregion
    //region 说明 : get
    //查询角色
    //简介 : 查询角色
    //步骤 :
    //1. 查询角色 : (√)
    // 根据条件参数查询角色(ROLE)；
    //2. 返回信息 : (√)
    // 根据条件参数和查询到的结果组装响应并返回；
    //endregion
    //region 参数 : get
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "is_paging", value = "是否分页", defaultValue = "true",required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_id", value = "角色编号",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_name", value = "角色名称",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_companyId", value = "筛选条件 : where role.companyId = #{equal_companyId}",required = false, dataType = "int", paramType = "query"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_is_paging", value = "是否分页", defaultValue = "true",required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_id", value = "筛选条件 : where role.id = #{_equal_id}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_name", value = "筛选条件 : where role.id = #{_equal_name}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_companyId", value = "筛选条件 : where role.companyId = #{_equal_companyId}",required = false, dataType = "int", paramType = "query"),
    })
    //endregion
    //region 请求 : get
    @RequestMapping(value = "/roles", method = RequestMethod.GET)
    //endregion
    public RoleGetModel get(Map<String, String> header, Map<String, Object> query) throws ServiceException {
        /* 查询角色 */
        //生成查询模型
        RoleCustomQueryModel queryModel = roleCustomConvertor.roleService_query2queryModel(query);
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        //查询实体
        List<RoleEntityExt> extList = null;
        String show = HzhrTypeUtil.object2string(query.get("_show"));
        if (!StringUtils.isEmpty(show)) {
            extList = roleDao.selectExtList1(queryModel);
        }
        //查询数量
        Integer total = null;
        Boolean showTotal = HzhrTypeUtil.object2boolean(query.get("_show_total"));
        if (showTotal != null && showTotal) {
            total = roleDao.selectCount(queryModel);
        }

        /* 返回信息 */
        RoleGetModel result = roleCustomConvertor.extList2roleGetModel(extList, total, null, query);
        return result;
    }

    //region javadoc注释 : get1
    /**
     * 查询角色 <br/><br/>
     * 简介&nbsp;:&nbsp;查询登录用户公司下的所有角色 <br/>
     * 步骤&nbsp;: <br/>
     * 1.&nbsp;查询角色&nbsp;:&nbsp;(√) <br/>
     * 根据条件参数查询角色(ROLE)对象集合roleList_1及总数， <br/>
     * 额外筛选条件如下： <br/>
     * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(1)&nbsp;根据登录用户.companyId查询用户的所属公司company_1，查询方式如下： <br/>
     * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;以GLOBAL方式调用companyService.get()服务获取CompanyModel模型对象作为company_1， <br/>
     * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CompanyModel模型对象与登录用户.companyId的对应关系如下： <br/>
     * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CompanyModel模型对象.id&nbsp;=&nbsp;登录用户.companyId； <br/>
     * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果company_1不存在，抛出异常201； <br/>
     * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果company_1.type&nbsp;=&nbsp;userOptions.getCode('COMPANY_TYPE','GAS_COMPANY'),那么， <br/>
     * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;roleList_1[i].id&nbsp;=&nbsp;1&nbsp;or&nbsp;roleList_1[i].id&nbsp;=&nbsp;2&nbsp;or&nbsp;roleList_1[i].companyId&nbsp;=&nbsp;登录用户.companyId； <br/>
     * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果company_1.type&nbsp;=&nbsp;userOptions.getCode('COMPANY_TYPE','IOT_DEVICE_COMPANY'),那么， <br/>
     * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;roleList_1[i].id&nbsp;=&nbsp;3&nbsp;or&nbsp;roleList_1[i].id&nbsp;=&nbsp;4&nbsp;or&nbsp;roleList_1[i].companyId&nbsp;=&nbsp;登录用户.companyId； <br/>
     * 2.&nbsp;返回信息&nbsp;:&nbsp;(√) <br/>
     * 根据条件参数和查询到的roleList_1及总数生成结果对象并返回； <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_total : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示总数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _is_paging : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否分页;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _page : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 页数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _count : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 每页数量;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @throws ServiceException <br/>
     * ROLESERVICE_GET1_201 : <br/>&nbsp&nbsp&nbsp&nbsp异常类型 : 业务流程异常<br/>&nbsp&nbsp&nbsp&nbsp异常业务 : 查询角色<br/>&nbsp&nbsp&nbsp&nbsp异常描述 : 登录用户的所属公司不存在<br/>
     * @see RoleGetModel result <br/>
     */ 
    //endregion
    //region 说明 : get1
    //查询角色
    //简介 : 查询登录用户公司下的所有角色
    //步骤 :
    //1. 查询角色 : (√)
    //根据条件参数查询角色(ROLE)对象集合roleList_1及总数，
    //额外筛选条件如下：
    //          (1) 根据登录用户.companyId查询用户的所属公司company_1，查询方式如下：
    //                    以GLOBAL方式调用companyService.get()服务获取CompanyModel模型对象作为company_1，
    //                    CompanyModel模型对象与登录用户.companyId的对应关系如下：
    //                              CompanyModel模型对象.id = 登录用户.companyId；
    //          如果company_1不存在，抛出异常201；
    //          如果company_1.type = userOptions.getCode('COMPANY_TYPE','GAS_COMPANY'),那么，
    //          roleList_1[i].id = 1 or roleList_1[i].id = 2 or roleList_1[i].companyId = 登录用户.companyId；
    //          如果company_1.type = userOptions.getCode('COMPANY_TYPE','IOT_DEVICE_COMPANY'),那么，
    //          roleList_1[i].id = 3 or roleList_1[i].id = 4 or roleList_1[i].companyId = 登录用户.companyId；
    //2. 返回信息 : (√)
    //根据条件参数和查询到的roleList_1及总数生成结果对象并返回；
    //endregion
    //region 参数 : get1
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "is_paging", value = "是否分页", defaultValue = "false",required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_is_paging", value = "是否分页", defaultValue = "false",required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
    })
    //endregion
    //region 请求 : get1
    @RequestMapping(value = "/v1/roles", method = RequestMethod.GET)
    //endregion
    public RoleGetModel get1(Map<String, String> header, Map<String, Object> query) throws ServiceException {
        /* 查询角色 */
        //生成查询模型
        Integer loginUserCompanyId = getCompanyId(header);
        if (loginUserCompanyId == null) {
            throw new ServiceException(User_ErrorsEnum.ROLESERVICE_GET1_201);
        }
        Map<String, Object> query1 = new HashMap<>();
        query1.put("_show", "one");
        query1.put("_show_info", true);
        query1.put("_equal_id", loginUserCompanyId);
        CompanyModel company_1 = companyService.get(initHeader(header, AccessModeEnum.GLOBAL), query1).getModel();
        if (company_1 == null) {
            throw new ServiceException(User_ErrorsEnum.ROLESERVICE_GET1_201);
        }
        RoleCustomQueryModel queryModel = roleCustomConvertor.roleService_query2queryModel(query);
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        String companyType_1 = company_1.getType();
        String gasCompanyTypeCode = userOptions.getCode(UserOptionsTypeName.COMPANY_TYPE, UserOptionsName.COMPANY_TYPE.GAS_COMPANY);
        String iotCompanyTypeCode = userOptions.getCode(UserOptionsTypeName.COMPANY_TYPE, UserOptionsName.COMPANY_TYPE.IOT_DEVICE_COMPANY);
        if (gasCompanyTypeCode.equals(companyType_1)) {
            queryModel.setCustom2(1);
            queryModel.setCustom3(2);
            queryModel.setCustom4(loginUserCompanyId);
        } else if (iotCompanyTypeCode.equals(companyType_1)) {
            queryModel.setCustom2(3);
            queryModel.setCustom3(4);
            queryModel.setCustom4(loginUserCompanyId);
        }
        //查询实体
        List<RoleEntityExt> extList = null;
        String show = HzhrTypeUtil.object2string(query.get("_show"));
        if (!StringUtils.isEmpty(show)) {
            extList = roleDao.selectExtList2(queryModel);
        }
        //查询数量
        Integer total = null;
        Boolean showTotal = HzhrTypeUtil.object2boolean(query.get("_show_total"));
        if (showTotal != null && showTotal) {
            total = roleDao.selectCount2(queryModel);
        }

        /* 返回信息 */
        RoleGetModel result = roleCustomConvertor.extList2roleGetModel(extList, total, null, query);
        return result;
    }
}











































































































































































































































































































































































































